import { app, BrowserWindow, ipcMain, Tray, Menu } from 'electron';
import { fileURLToPath } from 'url';
import path from 'path';
// @ts-ignore
import { startAides } from './aides.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const createWindow = () => {
    const win = new BrowserWindow({
        x: 2000,
        y: 750,
        width: 500,
        height: 600,
        frame: false,
        transparent: true,
        alwaysOnTop: true,
        webPreferences: {
            preload: `${__dirname}/preload.js`,
        },
    });

    win.setIgnoreMouseEvents(true);
    win.setSkipTaskbar(true);
    const tray = new Tray('./resources/tray.png');
    tray.setContextMenu(Menu.buildFromTemplate([
        { label: '退出', click: () => app.quit() },
        { label: '隐藏', click: () => win.hide() },
        { label: '显示', click: () => win.show() },
    ]));
    tray.setToolTip('我是你的人工智能助手');
    win.loadFile('index.html');
    win.webContents.openDevTools();
    startAides(win);
};

app.on('ready', () => {
    createWindow();
});

app.on('window-all-closed', () => {
    app.quit();
});